/**
 * 检测当前手机蓝牙是否开启
 */
const isBluetoothAvalibale = (onAvaliable, onError) => {
  uni.openBluetoothAdapter({
    mode: "central",
    success: res => {
      if (onAvaliable != null) {
        onAvaliable();
      }
    },
    fail: error => {
      if (error.state == 4) {
        uni.showToast({
          title: '请打开手机蓝牙',
          icon: "none"
        });
      } else if (error.state == 3) {
        uni.showToast({
          title: '请授权微信访问蓝牙',
          icon: "none"
        });
      } else if (error.state == 2) {
        uni.showToast({
          title: '蓝牙不支持',
          icon: "none"
        });
      } else if (error.state == 1) {
        uni.showToast({
          title: '蓝牙重置中',
          icon: "none"
        });
      } else {
		  console.log(error)
        uni.showToast({
          title: '当前蓝牙不可用',
          icon: "none"
        });
      }

      if (onError != null) {
        onError();
      }
    }
  });
};

module.exports = {
  isBluetoothAvalibale
};